import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
//字母异位词分组
//测试链接 https://leetcode.cn/problems/group-anagrams/
public class GroupAnagrams {
    public List<List<String>> groupAnagrams(String[] strs) {
        HashMap<String,List<String>> hash = new HashMap<>();

        for(String s : strs){
            char[] temp = s.toCharArray();
            Arrays.sort(temp);
            String str = new String(temp);
            if(!hash.containsKey(str)){
                hash.put(str,new ArrayList<>());
            }
            hash.get(str).add(str);
        }
        return new ArrayList<>(hash.values());
    }
}
